package cn.itcast.erp.utils;

import com.alibaba.fastjson.JSON;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 返回json格式数据
 */
public class AjaxReturnUtil {
    public static void JsonReturn(Boolean b, String message){
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("status", b);
        map.put("message", message);
        String jsonString = JSON.toJSONString(map);

        HttpServletResponse response = ServletActionContext.getResponse();
        response.setContentType("application/json; charset=utf-8");
        try {
            response.getWriter().print(jsonString);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
